﻿<!DOCTYPE html>
<html>
<head>
    <title>算法</title>
<style type="text/css">

</style>
</head>
<body>

<div>
<script type="text/javascript">
 //js去重
function distinct(arr){
	var hashObj = {},result =[];
	 for (var i=0,l=arr.length,item;(item = arr[i])!=null;i++)
		{
			//var item = arr[i];
			if(!hashObj[item]){
				hashObj[item] = true;
				result.push(item);
			}	
		}
	return result;
}

//借助sort排序把相同的元素放在一起
function unique4(array){
	array.sort();
	var re=[array[0]];
	for(var i = 1; i < array.length; i++){
		if( array[i] !== re[re.length-1])
		{
			re.push(array[i]);
		}
	}
	return re;
}

//sap单页应用开发；AJAX前端跨域；离线缓存优化；前端存储技术；性能优化；SASS使用；node开发，熟悉grunt和glup打包工具，熟悉express，mongondb,redis组件
//熟悉.NET编程；数据库开发；
console.log(JSON.stringify(distinct([2,23,3,42,22,34,34,54,'as','asd','zxcz','升水']))); 
console.log(JSON.stringify(unique4([2,23,3,42,22,34,34,54,'as','asa','asd','asc','zxcz','asd','升水'])));


function quickSort(arr){
	var l=arr.length;
	if(l <=1){
		return arr;
	}
	var left =[],right = [];
	var va = arr.splice(Math.floor(l/2),1)[0];
	for(var i =0;i<(l-1);i++){
		if(arr[i] > va){
			left.push(arr[i]);
		}else{
            right.push(arr[i]);
		}		
	}
return quickSort(left).concat([va],quickSort(right));
}

console.log(quickSort([23,45,67,32,489,45,4,3,56,67,563,53,357,87,97,9890,85,4,354,767,475,13,34,535,6,57]));

//数组分批
!function(){
	var arrparam = [1,3,54,65,34,76,8,324,67,89,56,43];
	var arrbox = [[],[],[],[]];
	var pl = arrparam.length;
	var bl = arrbox.length;
	var count = Math.floor(pl/bl);
	for(var x=0,z=0;x<pl;x++){
		arrbox[z].push(arrparam[x]);
		if((x+1)%count == 0){
	        z++;
		}
	}
	console.log(arrbox);
}()

</script>
</div>
</body>
</html>